package solutions.leetcode.normal;

import solutions.lib.BaseSolution;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/problems/bulls-and-cows/submissions/">299.猜数字游戏</a>
 */
public class Solution299 extends BaseSolution {

    public String getHint(String secret, String guess) {
        int[][] count = new int[10][2];
        int same = 0;
        for (int i = 0, len = secret.length(); i < len; i++) {
            char a = secret.charAt(i);
            char b = guess.charAt(i);
            if (a == b) {
                same ++;
            } else {
                count[a - '0'][0]++;
                count[b - '0'][1]++;
            }
        }
        String rst = same + "A";
        same = 0;
        for (int[] v : count) {
            same += Math.min(v[0], v[1]);
        }
        return rst + same + "B";
    }

    public static void main(String[] args) {
        Solution299 solution = new Solution299();
    }
}